package com.clippick;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import co.kr.clippick.R;

import com.clippick.common.Toasts;
import com.clippick.common.Utils;

public class NewFeedbackActivity extends Activity implements OnClickListener {
	private Context mContext;
	private ConnectivityManager manager;

	private Button backButton, sendButton;
	private LinearLayout backButtonLayer;
	private EditText commentEditText;
	private RatingBar ratingBar;
	private Button iOSButton, androidButton, winButton, macButton;

	private String commentString = "";
	private int ratingInt = 0;
	private List<String> deviceArray = new ArrayList<String>();
	String device = "";

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_feedback);

		mContext = this;

		manager = (ConnectivityManager) mContext
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		sendButton = (Button) findViewById(R.id.send_feedback_button);

		backButton = (Button) findViewById(R.id.back);
		backButtonLayer = (LinearLayout) findViewById(R.id.back_button_layer);
		commentEditText = (EditText) findViewById(R.id.comment);
		ratingBar = (RatingBar) findViewById(R.id.ratingbar);

		iOSButton = (Button) findViewById(R.id.ios);
		androidButton = (Button) findViewById(R.id.android);
		winButton = (Button) findViewById(R.id.windows);
		macButton = (Button) findViewById(R.id.mac);

		iOSButton.setOnClickListener(this);
		androidButton.setOnClickListener(this);
		winButton.setOnClickListener(this);
		macButton.setOnClickListener(this);

		sendButton.setOnClickListener(this);
		backButton.setOnClickListener(this);
		backButtonLayer.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.send_feedback_button:
			if (Utils.checkNetwokState(manager)) {
				ratingInt = (int) ratingBar.getRating();
				commentString = commentEditText.getText().toString();
				StringBuilder deviceBuilder = new StringBuilder();
				for (String item : deviceArray) {
					deviceBuilder.append(item).append(",");
				}

			} else {
				Toasts.showToast(mContext, getString(R.string.network_fail));
			}
			break;

		case R.id.back:
			finish();
			break;

		case R.id.back_button_layer:
			finish();
			break;

		case R.id.ios:
			if (deviceArray.contains("ios")) {
				// remove
				deviceArray.remove("ios");
			} else {
				// add
				deviceArray.add("ios");
			}
			break;

		case R.id.android:
			if (deviceArray.contains("android")) {
				// remove
				deviceArray.remove("android");
			} else {
				// add
				deviceArray.add("android");
			}
			break;

		case R.id.windows:
			if (deviceArray.contains("windows")) {
				// remove
				deviceArray.remove("windows");
			} else {
				// add
				deviceArray.add("windows");
			}
			break;

		case R.id.mac:
			if (deviceArray.contains("mac")) {
				// remove
				deviceArray.remove("mac");
			} else {
				// add
				deviceArray.add("mac");
			}
			break;
		}
	}
}
